home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / sbprolog / sbp.zoo / sbp_v3.1 / auxil / io.c < prev    next >
C/C++ Source or Header  |  1992-02-16  |  1KB  |  55 lines

  1. /*$Source: /usr/home/dhesi/booz/RCS/io.c,v $*/
  2. /*$Id: io.c,v 1.8 91/07/08 12:06:55 dhesi Exp $*/
  3. /***********************************************************
  4. Input/output for lzh decoding.
  5.  
  6. Adapted from "ar" archiver written by Haruhiko Okumura.
  7. ***********************************************************/
  8. #include "booz.h"
  9. #include "zoo.h"
  10. #include "ar.h"
  11. #include "lzh.h"
  12.  
  13. extern FILE *arcfile;
  14. t_uint16 bitbuf;
  15.  
  16. static uint  subbitbuf;
  17. static int   bitcount;
  18.  
  19. int fillbuf(int n)
  20. {
  21.     bitbuf <<= n;
  22.     while (n > bitcount) {
  23.         bitbuf |= subbitbuf << (n -= bitcount);
  24.         if (feof(arcfile))
  25.             subbitbuf = 0;
  26.         else
  27.             subbitbuf = (uchar) getc(arcfile);
  28.         bitcount = CHAR_BIT;
  29.     }
  30.     bitbuf |= subbitbuf >> (bitcount -= n);
  31. }
  32.  
  33. uint getbits(int n)
  34. {
  35.     uint x;
  36.  
  37.     x = bitbuf >> (BITBUFSIZ - n);  fillbuf(n);
  38.     return x;
  39. }
  40.  
  41. int fwrite_crc(uchar *p, int n, FILE *f)
  42. {
  43.     if (f != NULL) {
  44.         if (fwrite((char *) p, 1, n, f) < n) 
  45.             prterror('f', "disk full", (char *)0, (char *)0);
  46.     }
  47.     addbfcrc((char *) p, (unsigned) n);
  48. }
  49.  
  50. int init_getbits(void)
  51. {
  52.     bitbuf = 0;  subbitbuf = 0;  bitcount = 0;
  53.     fillbuf(BITBUFSIZ);
  54. }
  55.